home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / bbs / pad311.zip / CHECKNUM.MH < prev    next >
Text File  |  1996-08-21  |  8KB  |  242 lines

  1. #ifndef __CHECKNUM_MH
  2. #define __CHECKNUM_MH
  3.  
  4. #ifndef __MAX_MH
  5. #include <max.mh>
  6. #define __MAX_MH
  7. #endif
  8.  
  9. #ifndef __FILE_MH
  10. #include "file.mh"
  11. #endif
  12.  
  13. #ifndef __TIME_MH
  14. #include "time.mh"
  15. #endif
  16.  
  17. #ifndef __WILDCARD_MH
  18. #include "wildcard.mh"
  19. #endif
  20.  
  21. #ifndef __USER_MH
  22. #include "user.mh"
  23. #endif
  24.  
  25. #ifndef __STRING_MH
  26. #include "string.mh"
  27. #endif
  28.  
  29. #ifndef __SETTINGS_MH
  30. #include "settings.mh"
  31. #endif
  32.  
  33. #ifndef __FINDCHAR_MH
  34. #include "findchar.mh"
  35. #endif
  36.  
  37. #ifndef __STRIPSTR_MH
  38. #include "stripstr.mh"
  39. #endif
  40.  
  41. string:
  42.   phone_number, city;
  43.  
  44. // Given a phone number, this routine determines what actually
  45. // needs to be dialed to call that number. Returns
  46.  
  47. bool checkCallBackTime (struct _time: startTime, struct _time: endTime) {
  48.   struct _time: curTime;
  49.   bool: temp;
  50.  
  51.   getTime (curTime);
  52.   temp := betweenTimes (curTime, startTime, endTime);
  53.   if (temp = False) {
  54.     log (str_bad_time_log);
  55.     show (bad_time_file, str_bad_time1 + timeToString (startTime) 
  56.       + str_bad_time2 + timeToString (endTime) + str_bad_time3);
  57.     };
  58.   return temp;
  59.   }
  60.  
  61. int getNumToDial (string: filename, string: phoneNum) {
  62.   string: line, token, ldprefix, localprefix, 
  63.     file;
  64.   int: fd, idx, ldstart, ldlen, localstart, 
  65.     locallen, numberType, key;
  66.   struct _time: 
  67.     ldStartTime,
  68.     localStartTime,
  69.     ldEndTime,
  70.     localEndTime;
  71.  
  72.   numberType := DNLDLOCKOUT;
  73.   fd := open (filename, IOPEN_READ);
  74.   if (fd = -1) {
  75.     print (str_cant_open + filename + "\n");
  76.     log (str_cant_open_log + filename);
  77.     return DNLDLOCKOUT;
  78.     };
  79.  
  80.   for (;;) {
  81.     readln (fd,line);
  82.     stripRightOf (line,';');
  83.  
  84.     if (line [1] = '#') {
  85.       line := strtrim (line, " \t");
  86.       if (line <> "") {
  87.         idx := stridx (line, 1, ' ');
  88.         if (idx) {
  89.           token := substr (line,1,idx-1);
  90.           line  := strtrim (substr (line,idx,strlen (line) - idx + 1)," \t");
  91.           }
  92.         else {
  93.           token := line;
  94.           line := "";
  95.           };
  96.         token := strlower (token);
  97.         stripStr (token,"_");
  98.  
  99.         if (token = "#end") {
  100.           show (long_distance_file, str_ld_message);
  101.           log (str_ld_message_log);
  102.           return DNLDLOCKOUT;
  103.           };
  104.         if (token = "#starttime")       {strToTime (line, ldStartTime);
  105.                                         strToTime (line, localStartTime);};
  106.         if (token = "#endtime")         {strToTime (line, ldEndTime);
  107.                                         strToTime (line, localEndTime);};
  108.         if (token = "#lockout")         numberType := DNLOCKOUT;
  109.         if (token = "#ld")              numberType := DNLD;
  110.         if (token = "#ldlockout")       numberType := DNLDLOCKOUT;
  111.         if (token = "#local")           numberType := DNLOCAL;
  112.         if (token = "#asklocal")        numberType := DNASK;
  113.         if (token = "#ldprefix")        ldprefix := line;
  114.         if (token = "#ldstart")         ldstart := strtoi (line);
  115.         if (token = "#ldlen")           ldlen := strtoi (line);
  116.         if (token = "#localprefix")     localprefix := line;
  117.         if (token = "#localstart")      localstart := strtoi (line);
  118.         if (token = "#locallen")        locallen := strtoi (line);
  119.         if (token = "#ldstarttime")     strToTime (line, ldStartTime);
  120.         if (token = "#ldendtime");      strToTime (line, ldEndTime);
  121.         if (token = "#localstarttime")  strToTime (line, localStartTime);
  122.         if (token = "#localendtime")    strToTime (line, localEndTime);
  123.         if (token = "#write")           print (COL_WHITE + line + "\n");
  124.         if (token = "#file")            file := line;
  125.         if (token = "#city")            city := line;
  126.         if (token = "#endcity")         city := "";
  127.         };
  128.       }
  129.     else {
  130.       stripStr (line, " ()-\t");                // Remove formatting characters
  131.       if (matchWildcard (phoneNum, line)) {     // Does the user's phone number match?
  132.  
  133.         // First, ensure that the user's number type is set appropriately.
  134.  
  135.         if (numberType = DNASK) {               // If necessary, ask the user if his/her
  136.           key := input_list ("Yn", 0, "",       // phone number is local.
  137.             str_press_yn, str_ask_local);       //
  138.           if (key = 'Y') {                      // If the user says their phone is local,
  139.             numberType := DNLOCAL;              //   set the appropriate number type
  140.             }                                   //
  141.           else numberType := DNLD;              //   ditto for long distance.
  142.           };                                    //
  143.         if ((numberType = DNLD)                 // If the user's phone number is LD
  144.           and (num_allow_ld = False)) {         //   and LD numbers are not allowed
  145.           numberType := DNLDLOCKOUT;            //   set the number type to LDLOCKOUT.
  146.           };
  147.  
  148.         // Display the appropriate message to the user and record the appropriate
  149.         // string in the log file.
  150.  
  151.         if (city <> "") print (city + "\n");
  152.         show_file (file);
  153.  
  154.         if (numberType = DNLD) {
  155.           log (str_ld_ok_log);
  156.           show (ld_ok_file, str_ld_ok_message);
  157.           };
  158.         if (numberType = DNLOCAL) {
  159.           log (str_local_log);
  160.           show (local_file, str_local_message);
  161.           };
  162.         if (numberType = DNLOCKOUT) {
  163.           show (lockout_file, str_lockout_message);
  164.           log (str_lockout_log);
  165.           };
  166.         if (numberType = DNLDLOCKOUT) {
  167.           show (long_distance_file, str_ld_message);
  168.           log (str_ld_message_log);
  169.           };
  170.  
  171.         // Check to make sure the user is calling at the right time of day.
  172.  
  173.         if (numberType = DNLOCAL) {
  174.           if (checkCallBackTime (localStartTime, localEndTime) = False)
  175.             numberType := DNBADTIME;
  176.           }
  177.         else if (numberType = DNLD) {
  178.           if (checkCallBackTime (ldStartTime, ldEndTime) = False)
  179.             numberType := DNBADTIME;
  180.           };
  181.  
  182.         // Determine the number we have to dial to reach the user.
  183.  
  184.         if (numberType = DNLOCAL) {
  185.           phone_number := localprefix + substr (phoneNum, localstart, locallen);
  186.           }
  187.         else if (numberType = DNLD) {
  188.           phone_number := ldprefix + substr (phoneNum, ldstart, ldlen);
  189.           };
  190.         return numberType;
  191.         };
  192.       };
  193.     };
  194.   return DNLDLOCKOUT;
  195.   }
  196.  
  197. int phoneInUse (string: parsedPhone, Ref string: dupeName) {
  198.   long: idx;
  199.   struct _usr: u;
  200.  
  201.   for (;;) {
  202.     idx := findPhone (idx,u,parsedPhone, parsedPhone);
  203.     if (idx = -1) return False;
  204.     if ((u.name <> usr.name) and (u.deleted = False)) {
  205.       if (num_registered_dupes) {
  206.         if ((findAnyChars (u.xkeys, str_old_keys) = 0)
  207.           and (findAllChars (u.xkeys, str_new_keys))
  208.           and (u.priv >= class_to_priv (str_new_sec))) {
  209.           dupeName := u.name;
  210.           return True;
  211.           };
  212.         }
  213.       else {
  214.         dupeName := u.name;
  215.         return True;
  216.         };
  217.       };
  218.     idx := idx + 1;
  219.     };
  220.   return False;
  221.   }
  222.  
  223. int checkPhone (Ref string: parsedPhone) {
  224.   int: dialType;
  225.   string: dupeName;
  226.  
  227.   if (num_dupes) {
  228.     print (str_scanning_dupe);
  229.     if (phoneInUse (parsedPhone,dupeName)) {
  230.       log (str_dupe_found_log + dupeName);
  231.       show (dupe_found_file, str_dupe_found);
  232.       return DNDUPE;
  233.       };
  234.     };
  235.  
  236.   dialType := getNumToDial (phone_file, parsedPhone);
  237.  
  238.   return dialType;
  239.   }
  240.  
  241. #endif
  242.